package com.gzedu.module.service.meun.impl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.gzedu.common.sys.service.impl.BaseService;
import com.gzedu.common.util.page.Page;
import com.gzedu.module.dao.meun.IMeunDao;
import com.gzedu.module.modle.meun.Meun;
import com.gzedu.module.service.meun.IMeunService;

@Service
@Transactional(readOnly=false)
public class MeunService extends BaseService<Meun> implements IMeunService{
	@Autowired
	private IMeunDao meunDao;
	
	/**
	 * 获取所有的子节点
	 * @param meun
	 * @param child
	 * @return
	 */
	public Meun getAllChildren(Meun meun, List<Meun> child){
		List<Meun> childrens = new ArrayList<Meun>();
		if(child != null && child.size() > 0){
			for(Meun m : child){
				if(meun.getMeunCode().equals(m.getParent().getMeunCode())){
					childrens.add(m);
					meun.setChildren(childrens);
					getAllChildren(m,child);
				}
			}
		}
		return meun;
	}
	
	public List<Meun> getMeunTree(String parentCode, List<Meun> children, Meun meun){
		if(children != null && children.size() > 0){
			for(Meun m : children){
				
			}
		}
		return null;
	}

	public Page<Meun> findPage(Page<Meun> page) {
		// TODO Auto-generated method stub
		return meunDao.page(null, page.getPageNo(), page.getPageSize());
	}

	public List<Meun> findByRoleCode(String roleCode) {
		// TODO Auto-generated method stub
		return meunDao.findByRoleCode(roleCode);
	}
}
